package com.smart.community.admin.config;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import darabonba.core.client.ClientOverrideConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zhangwei
 */
@Configuration
@EnableConfigurationProperties(AliYunSmsConfigProperties.class)
public class AliYunSmsConfig {
    @Resource
    private AliYunSmsConfigProperties properties;


    @Bean
    public AsyncClient asyncClient() {
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder().accessKeyId(properties.getAccessKeyId()).accessKeySecret(properties.getAccessKeySecret()).build());
        return AsyncClient.builder()
                //
                .credentialsProvider(provider)
                //
                .overrideConfiguration(ClientOverrideConfiguration.create().setEndpointOverride(properties.getEndpoint()))
                //
                .build();
    }
}
